{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# 3.1安装Requests"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Requirement already satisfied: requests in /Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages\r\n"
     ]
    }
   ],
   "source": [
    "! pip install requests"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# 3.2获取响应内容"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "文本编码: UTF-8\n",
      "响应状态码: 200\n",
      "字符串方式的响应体: <!DOCTYPE html>\r\n",
      "<html lang=\"zh-CN\">\r\n",
      "<head>\r\n",
      "<meta charset=\"UTF-8\">\r\n",
      "<meta http-equiv=\"X-UA-Compatible\" content=\"IE=edge\">\r\n",
      "<meta name=\"viewport\" content=\"width=device-width, initial-scale=1, maximum-scale=1\">\r\n",
      "<title>大数据分析@唐松</title>\r\n",
      "<meta name=\"description\" content=\"唐松的个人博客，分享大数据分析和 Python 网络爬虫的思考。\" />\r\n",
      "<meta name=\"keywords\" content=\"唐松, Santos, 博客\" />\r\n",
      "<link rel=\"shortcut icon\" href=\"http://www.santostang.com/wp-content/themes/SongStyle-Two/images/favicon.ico\" type=\"image/x-icon\" />\r\n",
      "<link rel=\"stylesheet\" href=\"http://www.santostang.com/wp-content/themes/SongStyle-Two/css/bootstrap.min.css\">\r\n",
      "<link rel=\"stylesheet\" href=\"http://www.santostang.com/wp-content/themes/SongStyle-Two/css/font-awesome.min.css\">\r\n",
      "<script type=\"text/javascript\" src=\"http://www.santostang.com/wp-content/themes/SongStyle-Two/js/jquery.min.js\"></script>\r\n",
      "<script type=\"text/javascript\" src=\"http://www.santostang.com/wp-content/themes/SongStyle-Two/js/bootstrap.min.js\"></script>\r\n",
      "<link rel=\"stylesheet\" href=\"http://www.santostang.com/wp-content/themes/SongStyle-Two/style.css\">\r\n",
      "<link rel=\"pingback\" href=\"http://www.santostang.com/xmlrpc.php\" />\r\n",
      "<link rel='dns-prefetch' href='//s.w.org' />\n",
      "<link rel='stylesheet' id='crayon-css'  href='http://www.santostang.com/wp-content/plugins/crayon-syntax-highlighter/css/min/crayon.min.css?ver=_2.7.2_beta' type='text/css' media='all' />\n",
      "<link rel='stylesheet' id='crayon-theme-classic-css'  href='http://www.santostang.com/wp-content/plugins/crayon-syntax-highlighter/themes/classic/classic.css?ver=_2.7.2_beta' type='text/css' media='all' />\n",
      "<link rel='stylesheet' id='crayon-font-monaco-css'  href='http://www.santostang.com/wp-content/plugins/crayon-syntax-highlighter/fonts/monaco.css?ver=_2.7.2_beta' type='text/css' media='all' />\n",
      "<link rel='https://api.w.org/' href='http://www.santostang.com/wp-json/' />\n",
      "<script type=\"text/javascript\" src=\"http://www.santostang.com/wp-content/plugins/si-captcha-for-wordpress/captcha/si_captcha.js?ver=1494247699\"></script>\n",
      "<!-- begin SI CAPTCHA Anti-Spam - login/register form style -->\r\n",
      "<style type=\"text/css\">\r\n",
      ".si_captcha_small { width:175px; height:45px; padding-top:10px; padding-bottom:10px; }\n",
      ".si_captcha_large { width:250px; height:60px; padding-top:10px; padding-bottom:10px; }\n",
      "img#si_image_com { border-style:none; margin:0; padding-right:5px; float:left; }\n",
      "img#si_image_reg { border-style:none; margin:0; padding-right:5px; float:left; }\n",
      "img#si_image_log { border-style:none; margin:0; padding-right:5px; float:left; }\n",
      "img#si_image_side_login { border-style:none; margin:0; padding-right:5px; float:left; }\n",
      "img#si_image_checkout { border-style:none; margin:0; padding-right:5px; float:left; }\n",
      "img#si_image_jetpack { border-style:none; margin:0; padding-right:5px; float:left; }\n",
      "img#si_image_bbpress_topic { border-style:none; margin:0; padding-right:5px; float:left; }\n",
      ".si_captcha_refresh { border-style:none; margin:0; vertical-align:bottom; }\n",
      "div#si_captcha_input { display:block; padding-top:15px; padding-bottom:5px; }\n",
      "label#si_captcha_code_label { margin:0; }\n",
      "input#si_captcha_code_input { width:65px; }\n",
      "p#si_captcha_code { clear: left; padding-top:10px; }\n",
      ".si-captcha-jetpack-error { color:#DC3232; }\n",
      "</style>\r\n",
      "<!-- end SI CAPTCHA Anti-Spam - login/register form style -->\r\n",
      "</head>\r\n",
      "\r\n",
      "<body>\r\n",
      "<header id=\"header\">\r\n",
      "  <div class=\"avatar\"><img src=\"http://www.santostang.com/wp-content/themes/SongStyle-Two/images/avatar.jpg\" alt=\"大数据@唐松Santos\" class=\"img-circle\" width=\"50%\"></div>\r\n",
      "  <h3 id=\"name\">大数据@唐松Santos</h3>\r\n",
      "  <div class=\"sns\">\r\n",
      "    <a href=\"http://www.santostang.com/feed/\" target=\"_blank\" rel=\"nofollow\" title=\"RSS\"><i class=\"fa fa-rss\" aria-hidden=\"true\"></i></a>\r\n",
      "        <a href=\"http://weibo.com/santostang\" target=\"_blank\" rel=\"nofollow\" title=\"Weibo\"><i class=\"fa fa-weibo\" aria-hidden=\"true\"></i></a>\r\n",
      "                <a href=\"https://www.linkedin.com/in/santostang\" target=\"_blank\" rel=\"nofollow\" title=\"Linkedin\"><i class=\"fa fa-linkedin\" aria-hidden=\"true\"></i></a>\r\n",
      "                <a href=\"mailto:tangsongsky@gmail.com\" target=\"_blank\" rel=\"nofollow\" title=\"envelope\"><i class=\"fa fa-envelope\" aria-hidden=\"true\"></i></i></a>\r\n",
      "          </div>\r\n",
      "  <div class=\"nav\">\r\n",
      "   <ul><li class=\"current-menu-item\"><a href=\"http://www.santostang.com/\">首页</a></li>\n",
      "<li><a href=\"http://www.santostang.com/about-me/\">关于我</a></li>\n",
      "<li><a href=\"http://www.santostang.com/post-search/\">文章搜索</a></li>\n",
      "<li><a href=\"http://www.santostang.com/wp-login.php\">登录</a></li>\n",
      "</ul>  </div>\r\n",
      "</header>\n",
      "<div id=\"main\">\n",
      "  <div class=\"row box\">\n",
      "    <div class=\"col-md-8\">\n",
      "                  <article class=\"article-list-1 clearfix\">\n",
      "        <header class=\"clearfix\">\n",
      "          <h1 class=\"post-title\"><a href=\"http://www.santostang.com/2017/03/08/hello-python/\">Hello Python!</a></h1>\n",
      "          <div class=\"post-meta\">\n",
      "            <span class=\"meta-span\"><i class=\"fa fa-calendar\"></i> 03月08日</span>\n",
      "            <span class=\"meta-span\"><i class=\"fa fa-folder-open-o\"></i> <a href=\"http://www.santostang.com/category/big-data-marketing/\" rel=\"category tag\">大数据营销</a></span>\n",
      "            <span class=\"meta-span\"><i class=\"fa fa-commenting-o\"></i> <a href=\"http://www.santostang.com/2017/03/08/hello-python/#comments\" class=\"ds-thread-count\" data-thread-key=\"99\">3条评论</a></span>\n",
      "            <span class=\"meta-span hidden-xs\"><i class=\"fa fa-tags\" aria-hidden=\"true\"></i> </span>\n",
      "          </div>\n",
      "        </header>\n",
      "        <div class=\"post-content clearfix\">\n",
      "          <p>This is an article for testing. I use it to show the example in my book Web Scrappy by Python.\n",
      "</p>\n",
      "        </div>\n",
      "      </article>\n",
      "                        <article class=\"article-list-1 clearfix\">\n",
      "        <header class=\"clearfix\">\n",
      "          <h1 class=\"post-title\"><a href=\"http://www.santostang.com/2017/03/07/echarts%e5%ad%a6%e4%b9%a0%e7%ac%94%e8%ae%b02-%e5%8d%95%e9%a1%b5%e9%9d%a2%e5%a4%9a%e5%bc%a0%e5%9b%be%e8%a1%a8/\">echarts学习笔记(2) &#8212; 同一页面多图表</a></h1>\n",
      "          <div class=\"post-meta\">\n",
      "            <span class=\"meta-span\"><i class=\"fa fa-calendar\"></i> 03月07日</span>\n",
      "            <span class=\"meta-span\"><i class=\"fa fa-folder-open-o\"></i> <a href=\"http://www.santostang.com/category/big-data-marketing/\" rel=\"category tag\">大数据营销</a></span>\n",
      "            <span class=\"meta-span\"><i class=\"fa fa-commenting-o\"></i> <a href=\"http://www.santostang.com/2017/03/07/echarts%e5%ad%a6%e4%b9%a0%e7%ac%94%e8%ae%b02-%e5%8d%95%e9%a1%b5%e9%9d%a2%e5%a4%9a%e5%bc%a0%e5%9b%be%e8%a1%a8/#respond\" class=\"ds-thread-count\" data-thread-key=\"96\">没有评论</a></span>\n",
      "            <span class=\"meta-span hidden-xs\"><i class=\"fa fa-tags\" aria-hidden=\"true\"></i> </span>\n",
      "          </div>\n",
      "        </header>\n",
      "        <div class=\"post-content clearfix\">\n",
      "          <p>本文首发于 CSDN，当年，也就是2014年，我还是在大四的最后一个暑假，在 EMC 做实习，用 echarts做一个可视化的工具。\n",
      "\n",
      "在一个页面只是一个图表很简单，如果要在一个页面中添加多张图的话，怎么办呢？\n",
      "\n",
      "      \n",
      "\n",
      "...</p>\n",
      "        </div>\n",
      "      </article>\n",
      "                        <article class=\"article-list-1 clearfix\">\n",
      "        <header class=\"clearfix\">\n",
      "          <h1 class=\"post-title\"><a href=\"http://www.santostang.com/2017/03/07/echarts%e5%ad%a6%e4%b9%a0%e7%ac%94%e8%ae%b01-%e4%bd%bf%e7%94%a8%e6%a8%a1%e5%9d%97%e5%8c%96%e5%8d%95%e6%96%87%e4%bb%b6%e5%bc%95%e5%85%a5/\">echarts学习笔记(1) &#8212; 模块化单文件引入</a></h1>\n",
      "          <div class=\"post-meta\">\n",
      "            <span class=\"meta-span\"><i class=\"fa fa-calendar\"></i> 03月07日</span>\n",
      "            <span class=\"meta-span\"><i class=\"fa fa-folder-open-o\"></i> <a href=\"http://www.santostang.com/category/%e6%95%b0%e6%8d%ae%e5%8f%af%e8%a7%86%e5%8c%96/\" rel=\"category tag\">数据可视化</a></span>\n",
      "            <span class=\"meta-span\"><i class=\"fa fa-commenting-o\"></i> <a href=\"http://www.santostang.com/2017/03/07/echarts%e5%ad%a6%e4%b9%a0%e7%ac%94%e8%ae%b01-%e4%bd%bf%e7%94%a8%e6%a8%a1%e5%9d%97%e5%8c%96%e5%8d%95%e6%96%87%e4%bb%b6%e5%bc%95%e5%85%a5/#respond\" class=\"ds-thread-count\" data-thread-key=\"94\">没有评论</a></span>\n",
      "            <span class=\"meta-span hidden-xs\"><i class=\"fa fa-tags\" aria-hidden=\"true\"></i> <a href=\"http://www.santostang.com/tag/echarts/\" rel=\"tag\">Echarts</a>,<a href=\"http://www.santostang.com/tag/%e5%a4%a7%e6%95%b0%e6%8d%ae/\" rel=\"tag\">大数据</a>,<a href=\"http://www.santostang.com/tag/%e6%95%b0%e6%8d%ae%e5%8f%af%e8%a7%86%e5%8c%96/\" rel=\"tag\">数据可视化</a></span>\n",
      "          </div>\n",
      "        </header>\n",
      "        <div class=\"post-content clearfix\">\n",
      "          <p>本文首发于 CSDN，地址为：echarts学习笔记(1)。当年，也就是2014年，我还是在大四的最后一个暑假，在 EMC 做实习，用 echarts做一个可视化的工具。\n",
      "\n",
      "因为最近需要用到echarts来做 BI 商业智能工具, 而echarts相...</p>\n",
      "        </div>\n",
      "      </article>\n",
      "                        <article class=\"article-list-1 clearfix\">\n",
      "        <header class=\"clearfix\">\n",
      "          <h1 class=\"post-title\"><a href=\"http://www.santostang.com/2017/03/06/%e3%80%90%e7%88%ac%e8%99%ab%e4%ba%8c%e3%80%91%e7%88%ac%e8%99%ab%e7%9a%84%e6%a1%86%e6%9e%b6%e5%92%8c%e5%9f%ba%e6%9c%ac%e8%ae%ae%e9%a2%98/\">【爬虫二】爬虫的框架和基本议题</a></h1>\n",
      "          <div class=\"post-meta\">\n",
      "            <span class=\"meta-span\"><i class=\"fa fa-calendar\"></i> 03月06日</span>\n",
      "            <span class=\"meta-span\"><i class=\"fa fa-folder-open-o\"></i> <a href=\"http://www.santostang.com/category/python_web_scrappy/\" rel=\"category tag\">python 网络爬虫</a></span>\n",
      "            <span class=\"meta-span\"><i class=\"fa fa-commenting-o\"></i> <a href=\"http://www.santostang.com/2017/03/06/%e3%80%90%e7%88%ac%e8%99%ab%e4%ba%8c%e3%80%91%e7%88%ac%e8%99%ab%e7%9a%84%e6%a1%86%e6%9e%b6%e5%92%8c%e5%9f%ba%e6%9c%ac%e8%ae%ae%e9%a2%98/#respond\" class=\"ds-thread-count\" data-thread-key=\"93\">没有评论</a></span>\n",
      "            <span class=\"meta-span hidden-xs\"><i class=\"fa fa-tags\" aria-hidden=\"true\"></i> <a href=\"http://www.santostang.com/tag/python/\" rel=\"tag\">python</a>,<a href=\"http://www.santostang.com/tag/%e5%a4%a7%e6%95%b0%e6%8d%ae/\" rel=\"tag\">大数据</a>,<a href=\"http://www.santostang.com/tag/%e7%bd%91%e7%bb%9c%e7%88%ac%e8%99%ab/\" rel=\"tag\">网络爬虫</a></span>\n",
      "          </div>\n",
      "        </header>\n",
      "        <div class=\"post-content clearfix\">\n",
      "          <p>本文首发于知乎专栏，@唐松。链接：知乎专栏：【爬虫二】爬虫的框架和基本议题\n",
      "\n",
      "爬虫的技术文章很少有从整体角度来说的，这次就从一个宏观的角度出发，希望通过这篇文章说清楚三个问题：\n",
      "\n",
      "\n",
      "爬虫的流程是怎样的？\n",
      "...</p>\n",
      "        </div>\n",
      "      </article>\n",
      "                        <article class=\"article-list-1 clearfix\">\n",
      "        <header class=\"clearfix\">\n",
      "          <h1 class=\"post-title\"><a href=\"http://www.santostang.com/2017/03/06/%e3%80%90%e7%88%ac%e8%99%ab%e4%b8%80%e3%80%91%e6%9c%80%e7%ae%80%e5%8d%95%e7%9a%84%e7%88%ac%e8%99%ab%ef%bc%8c%e9%9b%b6%e5%9f%ba%e7%a1%80%e6%95%99%e5%ad%a6/\">【爬虫一】最简单的爬虫，零基础教学</a></h1>\n",
      "          <div class=\"post-meta\">\n",
      "            <span class=\"meta-span\"><i class=\"fa fa-calendar\"></i> 03月06日</span>\n",
      "            <span class=\"meta-span\"><i class=\"fa fa-folder-open-o\"></i> <a href=\"http://www.santostang.com/category/python_web_scrappy/\" rel=\"category tag\">python 网络爬虫</a></span>\n",
      "            <span class=\"meta-span\"><i class=\"fa fa-commenting-o\"></i> <a href=\"http://www.santostang.com/2017/03/06/%e3%80%90%e7%88%ac%e8%99%ab%e4%b8%80%e3%80%91%e6%9c%80%e7%ae%80%e5%8d%95%e7%9a%84%e7%88%ac%e8%99%ab%ef%bc%8c%e9%9b%b6%e5%9f%ba%e7%a1%80%e6%95%99%e5%ad%a6/#comments\" class=\"ds-thread-count\" data-thread-key=\"90\">1条评论</a></span>\n",
      "            <span class=\"meta-span hidden-xs\"><i class=\"fa fa-tags\" aria-hidden=\"true\"></i> <a href=\"http://www.santostang.com/tag/python/\" rel=\"tag\">python</a>,<a href=\"http://www.santostang.com/tag/%e5%a4%a7%e6%95%b0%e6%8d%ae/\" rel=\"tag\">大数据</a>,<a href=\"http://www.santostang.com/tag/%e7%bd%91%e7%bb%9c%e7%88%ac%e8%99%ab/\" rel=\"tag\">网络爬虫</a></span>\n",
      "          </div>\n",
      "        </header>\n",
      "        <div class=\"post-content clearfix\">\n",
      "          <p>爬虫在大数据时代占据了重要的位置，在网上有大量的公开数据可以轻松获取。\n",
      "\n",
      "爬虫入门其实非常简单，就算你是编程小白，也可以轻松爬下一些网站。下面就以爬大众点评 在深圳市搜索潮汕牛肉的结果为例，教大家学会...</p>\n",
      "        </div>\n",
      "      </article>\n",
      "                        <article class=\"article-list-1 clearfix\">\n",
      "        <header class=\"clearfix\">\n",
      "          <h1 class=\"post-title\"><a href=\"http://www.santostang.com/2017/03/02/hello-world/\">Hello world!</a></h1>\n",
      "          <div class=\"post-meta\">\n",
      "            <span class=\"meta-span\"><i class=\"fa fa-calendar\"></i> 03月02日</span>\n",
      "            <span class=\"meta-span\"><i class=\"fa fa-folder-open-o\"></i> <a href=\"http://www.santostang.com/category/bigdata/\" rel=\"category tag\">大数据</a>,<a href=\"http://www.santostang.com/category/big-data-marketing/\" rel=\"category tag\">大数据营销</a></span>\n",
      "            <span class=\"meta-span\"><i class=\"fa fa-commenting-o\"></i> <a href=\"http://www.santostang.com/2017/03/02/hello-world/#comments\" class=\"ds-thread-count\" data-thread-key=\"1\">22条评论</a></span>\n",
      "            <span class=\"meta-span hidden-xs\"><i class=\"fa fa-tags\" aria-hidden=\"true\"></i> </span>\n",
      "          </div>\n",
      "        </header>\n",
      "        <div class=\"post-content clearfix\">\n",
      "          <p>Welcome to WordPress. This is your first post. Edit or delete it, then start writing!</p>\n",
      "        </div>\n",
      "      </article>\n",
      "                  <nav style=\"float:right\">\n",
      "              </nav>\n",
      "    </div>\n",
      "    <div class=\"col-md-4 hidden-xs hidden-sm\">\n",
      "      \n",
      "<aside class=\"widget clearfix\">\n",
      "  <form id=\"searchform\" action=\"http://www.santostang.com\">\n",
      "    <div class=\"input-group\">\n",
      "      <input type=\"search\" class=\"form-control\" placeholder=\"搜索…\" value=\"\" name=\"s\">\n",
      "      <span class=\"input-group-btn\">\n",
      "      <button class=\"btn btn-default\" type=\"submit\"><i class=\"fa fa-search\" aria-hidden=\"true\"></i></button>\n",
      "      </span> </div>\n",
      "  </form>\n",
      "</aside>\n",
      "<aside class=\"widget clearfix\">\n",
      "  <h4 class=\"widget-title\">文章分类</h4>\n",
      "  <div class=\"widget-cat\">\n",
      "    <ul>\n",
      "      \t<li class=\"cat-item cat-item-3\"><a href=\"http://www.santostang.com/category/python_web_scrappy/\" >python 网络爬虫</a> (2)\n",
      "</li>\n",
      "\t<li class=\"cat-item cat-item-2\"><a href=\"http://www.santostang.com/category/bigdata/\" >大数据</a> (1)\n",
      "</li>\n",
      "\t<li class=\"cat-item cat-item-1\"><a href=\"http://www.santostang.com/category/big-data-marketing/\" >大数据营销</a> (3)\n",
      "</li>\n",
      "\t<li class=\"cat-item cat-item-9\"><a href=\"http://www.santostang.com/category/%e6%95%b0%e6%8d%ae%e5%8f%af%e8%a7%86%e5%8c%96/\" >数据可视化</a> (1)\n",
      "</li>\n",
      "    </ul>\n",
      "  </div>\n",
      "</aside>\n",
      "<aside class=\"widget clearfix\">\n",
      "  <h4 class=\"widget-title\">热门文章</h4>\n",
      "  <ul class=\"widget-hot\">\n",
      "    \n",
      "<li><a href=\"http://www.santostang.com/2017/03/02/hello-world/\" target=\"_blank\" >Hello world!</a></li>\n",
      "<li><a href=\"http://www.santostang.com/2017/03/08/hello-python/\" target=\"_blank\" >Hello Python!</a></li>\n",
      "<li><a href=\"http://www.santostang.com/2017/03/06/%e3%80%90%e7%88%ac%e8%99%ab%e4%b8%80%e3%80%91%e6%9c%80%e7%ae%80%e5%8d%95%e7%9a%84%e7%88%ac%e8%99%ab%ef%bc%8c%e9%9b%b6%e5%9f%ba%e7%a1%80%e6%95%99%e5%ad%a6/\" target=\"_blank\" >【爬虫一】最简单的爬虫，零基础教学</a></li>\n",
      "<li><a href=\"http://www.santostang.com/2017/03/06/%e3%80%90%e7%88%ac%e8%99%ab%e4%ba%8c%e3%80%91%e7%88%ac%e8%99%ab%e7%9a%84%e6%a1%86%e6%9e%b6%e5%92%8c%e5%9f%ba%e6%9c%ac%e8%ae%ae%e9%a2%98/\" target=\"_blank\" >【爬虫二】爬虫的框架和基本议题</a></li>\n",
      "<li><a href=\"http://www.santostang.com/2017/03/07/echarts%e5%ad%a6%e4%b9%a0%e7%ac%94%e8%ae%b01-%e4%bd%bf%e7%94%a8%e6%a8%a1%e5%9d%97%e5%8c%96%e5%8d%95%e6%96%87%e4%bb%b6%e5%bc%95%e5%85%a5/\" target=\"_blank\" >echarts学习笔记(1) -- 模块化单文件引入</a></li>\n",
      "<li><a href=\"http://www.santostang.com/2017/03/07/echarts%e5%ad%a6%e4%b9%a0%e7%ac%94%e8%ae%b02-%e5%8d%95%e9%a1%b5%e9%9d%a2%e5%a4%9a%e5%bc%a0%e5%9b%be%e8%a1%a8/\" target=\"_blank\" >echarts学习笔记(2) -- 同一页面多图表</a></li>  </ul>\n",
      "</aside>\n",
      "<aside class=\"widget clearfix\">\n",
      "  <h4 class=\"widget-title\">随机推荐</h4>\n",
      "  <ul class=\"widget-hot\">\n",
      "        <li><a href=\"http://www.santostang.com/2017/03/08/hello-python/\" title=\"Hello Python!\">Hello Python!</a></li>\n",
      "\t    <li><a href=\"http://www.santostang.com/2017/03/07/echarts%e5%ad%a6%e4%b9%a0%e7%ac%94%e8%ae%b01-%e4%bd%bf%e7%94%a8%e6%a8%a1%e5%9d%97%e5%8c%96%e5%8d%95%e6%96%87%e4%bb%b6%e5%bc%95%e5%85%a5/\" title=\"echarts学习笔记(1) &#8212; 模块化单文件引入\">echarts学习笔记(1) &#8212; 模块化单文件引入</a></li>\n",
      "\t    <li><a href=\"http://www.santostang.com/2017/03/07/echarts%e5%ad%a6%e4%b9%a0%e7%ac%94%e8%ae%b02-%e5%8d%95%e9%a1%b5%e9%9d%a2%e5%a4%9a%e5%bc%a0%e5%9b%be%e8%a1%a8/\" title=\"echarts学习笔记(2) &#8212; 同一页面多图表\">echarts学习笔记(2) &#8212; 同一页面多图表</a></li>\n",
      "\t    <li><a href=\"http://www.santostang.com/2017/03/06/%e3%80%90%e7%88%ac%e8%99%ab%e4%ba%8c%e3%80%91%e7%88%ac%e8%99%ab%e7%9a%84%e6%a1%86%e6%9e%b6%e5%92%8c%e5%9f%ba%e6%9c%ac%e8%ae%ae%e9%a2%98/\" title=\"【爬虫二】爬虫的框架和基本议题\">【爬虫二】爬虫的框架和基本议题</a></li>\n",
      "\t    <li><a href=\"http://www.santostang.com/2017/03/02/hello-world/\" title=\"Hello world!\">Hello world!</a></li>\n",
      "\t    <li><a href=\"http://www.santostang.com/2017/03/06/%e3%80%90%e7%88%ac%e8%99%ab%e4%b8%80%e3%80%91%e6%9c%80%e7%ae%80%e5%8d%95%e7%9a%84%e7%88%ac%e8%99%ab%ef%bc%8c%e9%9b%b6%e5%9f%ba%e7%a1%80%e6%95%99%e5%ad%a6/\" title=\"【爬虫一】最简单的爬虫，零基础教学\">【爬虫一】最简单的爬虫，零基础教学</a></li>\n",
      "\t  </ul>\n",
      "</aside>\n",
      "<aside class=\"widget clearfix\">\n",
      "  <h4 class=\"widget-title\">标签云</h4>\n",
      "  <div class=\"widget-tags\">\n",
      "    <a href='http://www.santostang.com/tag/echarts/' class='tag-link-11 tag-link-position-1' title='1个话题' style=\"color:#56a811;font-size: 8pt;;\">Echarts</a>\n",
      "<a href='http://www.santostang.com/tag/python/' class='tag-link-6 tag-link-position-2' title='2个话题' style=\"color:#cd84ea;font-size: 16.4pt;;\">python</a>\n",
      "<a href='http://www.santostang.com/tag/%e5%a4%a7%e6%95%b0%e6%8d%ae/' class='tag-link-8 tag-link-position-3' title='3个话题' style=\"color:#94a30d;font-size: 22pt;;\">大数据</a>\n",
      "<a href='http://www.santostang.com/tag/%e6%95%b0%e6%8d%ae%e5%8f%af%e8%a7%86%e5%8c%96/' class='tag-link-10 tag-link-position-4' title='1个话题' style=\"color:#571f73;font-size: 8pt;;\">数据可视化</a>\n",
      "<a href='http://www.santostang.com/tag/%e7%bd%91%e7%bb%9c%e7%88%ac%e8%99%ab/' class='tag-link-7 tag-link-position-5' title='2个话题' style=\"color:#1178d4;font-size: 16.4pt;;\">网络爬虫</a>  </div>\n",
      "</aside>\n",
      "<aside class=\"widget clearfix\">\n",
      "  <h4 class=\"widget-title\">友情链接</h4>\n",
      "  <ul class=\"widget-links\">\n",
      "    <li><a href=\"http://www.santostang.com/wp-login.php\">登录</a></li>\n",
      "  </ul>\n",
      "</aside>\n",
      "    </div>\n",
      "  </div>\n",
      "</div>\n",
      "\n",
      "<footer id=\"footer\">\n",
      "  <div class=\"copyright\">\n",
      "    <p><i class=\"fa fa-copyright\" aria-hidden=\"true\"></i> 2017 <b>大数据@唐松Santos</b></p>\n",
      "    <p>Powered by <b>WordPress</b>. Theme by <a href=\"http://tangjie.me/jiestyle\" title=\"JieStyle\" target=\"_blank\"><b>JieStyle Two</b></a> | </p>\n",
      "  </div>\n",
      "  <div style=\"display:none;\">  </div>\n",
      "</footer>\n",
      "<script type=\"text/javascript\" src=\"http://www.santostang.com/wp-content/themes/SongStyle-Two/js/skel.min.js\"></script> \n",
      "<script type=\"text/javascript\" src=\"http://www.santostang.com/wp-content/themes/SongStyle-Two/js/util.min.js\"></script> \n",
      "<script type=\"text/javascript\" src=\"http://www.santostang.com/wp-content/themes/SongStyle-Two/js/nav.js\"></script>\n",
      "<script type='text/javascript' src='http://www.santostang.com/wp-includes/js/jquery/jquery.js?ver=1.12.4'></script>\n",
      "<script type='text/javascript' src='http://www.santostang.com/wp-includes/js/jquery/jquery-migrate.min.js?ver=1.4.1'></script>\n",
      "<script type='text/javascript'>\n",
      "/* <![CDATA[ */\n",
      "var CrayonSyntaxSettings = {\"version\":\"_2.7.2_beta\",\"is_admin\":\"0\",\"ajaxurl\":\"http:\\/\\/www.santostang.com\\/wp-admin\\/admin-ajax.php\",\"prefix\":\"crayon-\",\"setting\":\"crayon-setting\",\"selected\":\"crayon-setting-selected\",\"changed\":\"crayon-setting-changed\",\"special\":\"crayon-setting-special\",\"orig_value\":\"data-orig-value\",\"debug\":\"\"};\n",
      "var CrayonSyntaxStrings = {\"copy\":\"\\u4f7f\\u7528 %s \\u590d\\u5236\\uff0c\\u4f7f\\u7528 %s \\u7c98\\u8d34\\u3002\",\"minimize\":\"\\u70b9\\u51fb\\u5c55\\u5f00\\u4ee3\\u7801\"};\n",
      "/* ]]> */\n",
      "</script>\n",
      "<script type='text/javascript' src='http://www.santostang.com/wp-content/plugins/crayon-syntax-highlighter/js/min/crayon.min.js?ver=_2.7.2_beta'></script>\n",
      "<script type='text/javascript' src='http://www.santostang.com/wp-includes/js/wp-embed.min.js?ver=4.7.4'></script>\n",
      "<script>\n",
      "(function(){\n",
      "    var bp = document.createElement('script');\n",
      "    var curProtocol = window.location.protocol.split(':')[0];\n",
      "    if (curProtocol === 'https') {\n",
      "        bp.src = 'https://zz.bdstatic.com/linksubmit/push.js';        \n",
      "    }\n",
      "    else {\n",
      "        bp.src = 'http://push.zhanzhang.baidu.com/push.js';\n",
      "    }\n",
      "    var s = document.getElementsByTagName(\"script\")[0];\n",
      "    s.parentNode.insertBefore(bp, s);\n",
      "})();\n",
      "</script>\n",
      "</body>\n",
      "</html>\n"
     ]
    }
   ],
   "source": [
    "import requests\n",
    "r = requests.get('http://www.santostang.com/')\n",
    "print (\"文本编码:\", r.encoding)\n",
    "print (\"响应状态码:\", r.status_code)\n",
    "print (\"字符串方式的响应体:\", r.text)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# 3.3定制Requests"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 3.3.1\t传递URL参数"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "URL已经正确编码: http://httpbin.org/get?key1=value1&key2=value2\n",
      "字符串方式的响应体: \n",
      " {\n",
      "  \"args\": {\n",
      "    \"key1\": \"value1\", \n",
      "    \"key2\": \"value2\"\n",
      "  }, \n",
      "  \"headers\": {\n",
      "    \"Accept\": \"*/*\", \n",
      "    \"Accept-Encoding\": \"gzip, deflate\", \n",
      "    \"Connection\": \"close\", \n",
      "    \"Host\": \"httpbin.org\", \n",
      "    \"User-Agent\": \"python-requests/2.12.4\"\n",
      "  }, \n",
      "  \"origin\": \"116.49.102.8\", \n",
      "  \"url\": \"http://httpbin.org/get?key1=value1&key2=value2\"\n",
      "}\n",
      "\n"
     ]
    }
   ],
   "source": [
    "import requests\n",
    "key_dict = {'key1': 'value1', 'key2': 'value2'}\n",
    "r = requests.get('http://httpbin.org/get', params=key_dict)\n",
    "print (\"URL已经正确编码:\", r.url)\n",
    "print (\"字符串方式的响应体: \\n\", r.text)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 3.3.2\t定制请求头"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "响应状态码: 200\n"
     ]
    }
   ],
   "source": [
    "import requests\n",
    "headers = {\n",
    "'user-agent': 'Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/52.0.2743.82 Safari/537.36',\n",
    "'Host': 'www.santostang.com'\n",
    "}\n",
    "r = requests.get('http://www.santostang.com/', headers=headers)\n",
    "print (\"响应状态码:\", r.status_code)\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 3.3.3\t发送POST请求\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{\n",
      "  \"args\": {}, \n",
      "  \"data\": \"\", \n",
      "  \"files\": {}, \n",
      "  \"form\": {\n",
      "    \"key1\": \"value1\", \n",
      "    \"key2\": \"value2\"\n",
      "  }, \n",
      "  \"headers\": {\n",
      "    \"Accept\": \"*/*\", \n",
      "    \"Accept-Encoding\": \"gzip, deflate\", \n",
      "    \"Connection\": \"close\", \n",
      "    \"Content-Length\": \"23\", \n",
      "    \"Content-Type\": \"application/x-www-form-urlencoded\", \n",
      "    \"Host\": \"httpbin.org\", \n",
      "    \"User-Agent\": \"python-requests/2.12.4\"\n",
      "  }, \n",
      "  \"json\": null, \n",
      "  \"origin\": \"116.49.102.8\", \n",
      "  \"url\": \"http://httpbin.org/post\"\n",
      "}\n",
      "\n"
     ]
    }
   ],
   "source": [
    "import requests\n",
    "key_dict = {'key1': 'value1', 'key2': 'value2'}\n",
    "r = requests.post('http://httpbin.org/post', data=key_dict)\n",
    "print (r.text)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{\"message\":\"Not Found\",\"documentation_url\":\"https://developer.github.com/v3\"}\n"
     ]
    }
   ],
   "source": [
    "import json\n",
    "import requests\n",
    "url = 'https://api.github.com/some/endpoint'\n",
    "key = {'some':'data'}\n",
    "r = requests.post(url, data=json.dumps(key))\n",
    "print (r.text)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 3.3.4\t超时\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {},
   "outputs": [
    {
     "ename": "ConnectTimeout",
     "evalue": "HTTPConnectionPool(host='www.santostang.com', port=80): Max retries exceeded with url: / (Caused by ConnectTimeoutError(<requests.packages.urllib3.connection.HTTPConnection object at 0x00000000077806D8>, 'Connection to www.santostang.com timed out. (connect timeout=0.001)'))",
     "output_type": "error",
     "traceback": [
      "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
      "\u001b[0;31mtimeout\u001b[0m                                   Traceback (most recent call last)",
      "\u001b[0;32mC:\\ProgramData\\Anaconda3\\lib\\site-packages\\requests\\packages\\urllib3\\connection.py\u001b[0m in \u001b[0;36m_new_conn\u001b[0;34m(self)\u001b[0m\n\u001b[1;32m    137\u001b[0m             conn = connection.create_connection(\n\u001b[0;32m--> 138\u001b[0;31m                 (self.host, self.port), self.timeout, **extra_kw)\n\u001b[0m\u001b[1;32m    139\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n",
      "\u001b[0;32mC:\\ProgramData\\Anaconda3\\lib\\site-packages\\requests\\packages\\urllib3\\util\\connection.py\u001b[0m in \u001b[0;36mcreate_connection\u001b[0;34m(address, timeout, source_address, socket_options)\u001b[0m\n\u001b[1;32m     97\u001b[0m     \u001b[1;32mif\u001b[0m \u001b[0merr\u001b[0m \u001b[1;32mis\u001b[0m \u001b[1;32mnot\u001b[0m \u001b[1;32mNone\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m---> 98\u001b[0;31m         \u001b[1;32mraise\u001b[0m \u001b[0merr\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m     99\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n",
      "\u001b[0;32mC:\\ProgramData\\Anaconda3\\lib\\site-packages\\requests\\packages\\urllib3\\util\\connection.py\u001b[0m in \u001b[0;36mcreate_connection\u001b[0;34m(address, timeout, source_address, socket_options)\u001b[0m\n\u001b[1;32m     87\u001b[0m                 \u001b[0msock\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mbind\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0msource_address\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m---> 88\u001b[0;31m             \u001b[0msock\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mconnect\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0msa\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m     89\u001b[0m             \u001b[1;32mreturn\u001b[0m \u001b[0msock\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n",
      "\u001b[0;31mtimeout\u001b[0m: timed out",
      "\nDuring handling of the above exception, another exception occurred:\n",
      "\u001b[0;31mConnectTimeoutError\u001b[0m                       Traceback (most recent call last)",
      "\u001b[0;32mC:\\ProgramData\\Anaconda3\\lib\\site-packages\\requests\\packages\\urllib3\\connectionpool.py\u001b[0m in \u001b[0;36murlopen\u001b[0;34m(self, method, url, body, headers, retries, redirect, assert_same_host, timeout, pool_timeout, release_conn, chunked, **response_kw)\u001b[0m\n\u001b[1;32m    593\u001b[0m                                                   \u001b[0mbody\u001b[0m\u001b[1;33m=\u001b[0m\u001b[0mbody\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mheaders\u001b[0m\u001b[1;33m=\u001b[0m\u001b[0mheaders\u001b[0m\u001b[1;33m,\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m--> 594\u001b[0;31m                                                   chunked=chunked)\n\u001b[0m\u001b[1;32m    595\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n",
      "\u001b[0;32mC:\\ProgramData\\Anaconda3\\lib\\site-packages\\requests\\packages\\urllib3\\connectionpool.py\u001b[0m in \u001b[0;36m_make_request\u001b[0;34m(self, conn, method, url, timeout, chunked, **httplib_request_kw)\u001b[0m\n\u001b[1;32m    360\u001b[0m         \u001b[1;32melse\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m--> 361\u001b[0;31m             \u001b[0mconn\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mrequest\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mmethod\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0murl\u001b[0m\u001b[1;33m,\u001b[0m \u001b[1;33m**\u001b[0m\u001b[0mhttplib_request_kw\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m    362\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n",
      "\u001b[0;32mC:\\ProgramData\\Anaconda3\\lib\\http\\client.py\u001b[0m in \u001b[0;36mrequest\u001b[0;34m(self, method, url, body, headers, encode_chunked)\u001b[0m\n\u001b[1;32m   1238\u001b[0m         \u001b[1;34m\"\"\"Send a complete request to the server.\"\"\"\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m-> 1239\u001b[0;31m         \u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0m_send_request\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mmethod\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0murl\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mbody\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mheaders\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mencode_chunked\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m   1240\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n",
      "\u001b[0;32mC:\\ProgramData\\Anaconda3\\lib\\http\\client.py\u001b[0m in \u001b[0;36m_send_request\u001b[0;34m(self, method, url, body, headers, encode_chunked)\u001b[0m\n\u001b[1;32m   1284\u001b[0m             \u001b[0mbody\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0m_encode\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mbody\u001b[0m\u001b[1;33m,\u001b[0m \u001b[1;34m'body'\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m-> 1285\u001b[0;31m         \u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mendheaders\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mbody\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mencode_chunked\u001b[0m\u001b[1;33m=\u001b[0m\u001b[0mencode_chunked\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m   1286\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n",
      "\u001b[0;32mC:\\ProgramData\\Anaconda3\\lib\\http\\client.py\u001b[0m in \u001b[0;36mendheaders\u001b[0;34m(self, message_body, encode_chunked)\u001b[0m\n\u001b[1;32m   1233\u001b[0m             \u001b[1;32mraise\u001b[0m \u001b[0mCannotSendHeader\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m-> 1234\u001b[0;31m         \u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0m_send_output\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mmessage_body\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mencode_chunked\u001b[0m\u001b[1;33m=\u001b[0m\u001b[0mencode_chunked\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m   1235\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n",
      "\u001b[0;32mC:\\ProgramData\\Anaconda3\\lib\\http\\client.py\u001b[0m in \u001b[0;36m_send_output\u001b[0;34m(self, message_body, encode_chunked)\u001b[0m\n\u001b[1;32m   1025\u001b[0m         \u001b[1;32mdel\u001b[0m \u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0m_buffer\u001b[0m\u001b[1;33m[\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m]\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m-> 1026\u001b[0;31m         \u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0msend\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mmsg\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m   1027\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n",
      "\u001b[0;32mC:\\ProgramData\\Anaconda3\\lib\\http\\client.py\u001b[0m in \u001b[0;36msend\u001b[0;34m(self, data)\u001b[0m\n\u001b[1;32m    963\u001b[0m             \u001b[1;32mif\u001b[0m \u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mauto_open\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m--> 964\u001b[0;31m                 \u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mconnect\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m    965\u001b[0m             \u001b[1;32melse\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n",
      "\u001b[0;32mC:\\ProgramData\\Anaconda3\\lib\\site-packages\\requests\\packages\\urllib3\\connection.py\u001b[0m in \u001b[0;36mconnect\u001b[0;34m(self)\u001b[0m\n\u001b[1;32m    162\u001b[0m     \u001b[1;32mdef\u001b[0m \u001b[0mconnect\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mself\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m--> 163\u001b[0;31m         \u001b[0mconn\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0m_new_conn\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m    164\u001b[0m         \u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0m_prepare_conn\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mconn\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n",
      "\u001b[0;32mC:\\ProgramData\\Anaconda3\\lib\\site-packages\\requests\\packages\\urllib3\\connection.py\u001b[0m in \u001b[0;36m_new_conn\u001b[0;34m(self)\u001b[0m\n\u001b[1;32m    142\u001b[0m                 \u001b[0mself\u001b[0m\u001b[1;33m,\u001b[0m \u001b[1;34m\"Connection to %s timed out. (connect timeout=%s)\"\u001b[0m \u001b[1;33m%\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m--> 143\u001b[0;31m                 (self.host, self.timeout))\n\u001b[0m\u001b[1;32m    144\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n",
      "\u001b[0;31mConnectTimeoutError\u001b[0m: (<requests.packages.urllib3.connection.HTTPConnection object at 0x00000000077806D8>, 'Connection to www.santostang.com timed out. (connect timeout=0.001)')",
      "\nDuring handling of the above exception, another exception occurred:\n",
      "\u001b[0;31mMaxRetryError\u001b[0m                             Traceback (most recent call last)",
      "\u001b[0;32mC:\\ProgramData\\Anaconda3\\lib\\site-packages\\requests\\adapters.py\u001b[0m in \u001b[0;36msend\u001b[0;34m(self, request, stream, timeout, verify, cert, proxies)\u001b[0m\n\u001b[1;32m    422\u001b[0m                     \u001b[0mretries\u001b[0m\u001b[1;33m=\u001b[0m\u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mmax_retries\u001b[0m\u001b[1;33m,\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m--> 423\u001b[0;31m                     \u001b[0mtimeout\u001b[0m\u001b[1;33m=\u001b[0m\u001b[0mtimeout\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m    424\u001b[0m                 )\n",
      "\u001b[0;32mC:\\ProgramData\\Anaconda3\\lib\\site-packages\\requests\\packages\\urllib3\\connectionpool.py\u001b[0m in \u001b[0;36murlopen\u001b[0;34m(self, method, url, body, headers, retries, redirect, assert_same_host, timeout, pool_timeout, release_conn, chunked, **response_kw)\u001b[0m\n\u001b[1;32m    642\u001b[0m             retries = retries.increment(method, url, error=e, _pool=self,\n\u001b[0;32m--> 643\u001b[0;31m                                         _stacktrace=sys.exc_info()[2])\n\u001b[0m\u001b[1;32m    644\u001b[0m             \u001b[0mretries\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0msleep\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n",
      "\u001b[0;32mC:\\ProgramData\\Anaconda3\\lib\\site-packages\\requests\\packages\\urllib3\\util\\retry.py\u001b[0m in \u001b[0;36mincrement\u001b[0;34m(self, method, url, response, error, _pool, _stacktrace)\u001b[0m\n\u001b[1;32m    362\u001b[0m         \u001b[1;32mif\u001b[0m \u001b[0mnew_retry\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mis_exhausted\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m--> 363\u001b[0;31m             \u001b[1;32mraise\u001b[0m \u001b[0mMaxRetryError\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0m_pool\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0murl\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0merror\u001b[0m \u001b[1;32mor\u001b[0m \u001b[0mResponseError\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mcause\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m    364\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n",
      "\u001b[0;31mMaxRetryError\u001b[0m: HTTPConnectionPool(host='www.santostang.com', port=80): Max retries exceeded with url: / (Caused by ConnectTimeoutError(<requests.packages.urllib3.connection.HTTPConnection object at 0x00000000077806D8>, 'Connection to www.santostang.com timed out. (connect timeout=0.001)'))",
      "\nDuring handling of the above exception, another exception occurred:\n",
      "\u001b[0;31mConnectTimeout\u001b[0m                            Traceback (most recent call last)",
      "\u001b[0;32m<ipython-input-12-c7ffbf8da38c>\u001b[0m in \u001b[0;36m<module>\u001b[0;34m()\u001b[0m\n\u001b[1;32m      1\u001b[0m \u001b[1;32mimport\u001b[0m \u001b[0mrequests\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m      2\u001b[0m \u001b[0mlink\u001b[0m \u001b[1;33m=\u001b[0m \u001b[1;34m\"http://www.santostang.com/\"\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m----> 3\u001b[0;31m \u001b[0mr\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mrequests\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mget\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mlink\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mtimeout\u001b[0m\u001b[1;33m=\u001b[0m \u001b[1;36m0.001\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m",
      "\u001b[0;32mC:\\ProgramData\\Anaconda3\\lib\\site-packages\\requests\\api.py\u001b[0m in \u001b[0;36mget\u001b[0;34m(url, params, **kwargs)\u001b[0m\n\u001b[1;32m     68\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m     69\u001b[0m     \u001b[0mkwargs\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0msetdefault\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;34m'allow_redirects'\u001b[0m\u001b[1;33m,\u001b[0m \u001b[1;32mTrue\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m---> 70\u001b[0;31m     \u001b[1;32mreturn\u001b[0m \u001b[0mrequest\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;34m'get'\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0murl\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mparams\u001b[0m\u001b[1;33m=\u001b[0m\u001b[0mparams\u001b[0m\u001b[1;33m,\u001b[0m \u001b[1;33m**\u001b[0m\u001b[0mkwargs\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m     71\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m     72\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n",
      "\u001b[0;32mC:\\ProgramData\\Anaconda3\\lib\\site-packages\\requests\\api.py\u001b[0m in \u001b[0;36mrequest\u001b[0;34m(method, url, **kwargs)\u001b[0m\n\u001b[1;32m     54\u001b[0m     \u001b[1;31m# cases, and look like a memory leak in others.\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m     55\u001b[0m     \u001b[1;32mwith\u001b[0m \u001b[0msessions\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mSession\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;33m)\u001b[0m \u001b[1;32mas\u001b[0m \u001b[0msession\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m---> 56\u001b[0;31m         \u001b[1;32mreturn\u001b[0m \u001b[0msession\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mrequest\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mmethod\u001b[0m\u001b[1;33m=\u001b[0m\u001b[0mmethod\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0murl\u001b[0m\u001b[1;33m=\u001b[0m\u001b[0murl\u001b[0m\u001b[1;33m,\u001b[0m \u001b[1;33m**\u001b[0m\u001b[0mkwargs\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m     57\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m     58\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n",
      "\u001b[0;32mC:\\ProgramData\\Anaconda3\\lib\\site-packages\\requests\\sessions.py\u001b[0m in \u001b[0;36mrequest\u001b[0;34m(self, method, url, params, data, headers, cookies, files, auth, timeout, allow_redirects, proxies, hooks, stream, verify, cert, json)\u001b[0m\n\u001b[1;32m    486\u001b[0m         }\n\u001b[1;32m    487\u001b[0m         \u001b[0msend_kwargs\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mupdate\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0msettings\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m--> 488\u001b[0;31m         \u001b[0mresp\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0msend\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mprep\u001b[0m\u001b[1;33m,\u001b[0m \u001b[1;33m**\u001b[0m\u001b[0msend_kwargs\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m    489\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m    490\u001b[0m         \u001b[1;32mreturn\u001b[0m \u001b[0mresp\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n",
      "\u001b[0;32mC:\\ProgramData\\Anaconda3\\lib\\site-packages\\requests\\sessions.py\u001b[0m in \u001b[0;36msend\u001b[0;34m(self, request, **kwargs)\u001b[0m\n\u001b[1;32m    607\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m    608\u001b[0m         \u001b[1;31m# Send the request\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m--> 609\u001b[0;31m         \u001b[0mr\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0madapter\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0msend\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mrequest\u001b[0m\u001b[1;33m,\u001b[0m \u001b[1;33m**\u001b[0m\u001b[0mkwargs\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m    610\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m    611\u001b[0m         \u001b[1;31m# Total elapsed time of the request (approximately)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n",
      "\u001b[0;32mC:\\ProgramData\\Anaconda3\\lib\\site-packages\\requests\\adapters.py\u001b[0m in \u001b[0;36msend\u001b[0;34m(self, request, stream, timeout, verify, cert, proxies)\u001b[0m\n\u001b[1;32m    477\u001b[0m                 \u001b[1;31m# TODO: Remove this in 3.0.0: see #2811\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m    478\u001b[0m                 \u001b[1;32mif\u001b[0m \u001b[1;32mnot\u001b[0m \u001b[0misinstance\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0me\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mreason\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mNewConnectionError\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m--> 479\u001b[0;31m                     \u001b[1;32mraise\u001b[0m \u001b[0mConnectTimeout\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0me\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mrequest\u001b[0m\u001b[1;33m=\u001b[0m\u001b[0mrequest\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m    480\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m    481\u001b[0m             \u001b[1;32mif\u001b[0m \u001b[0misinstance\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0me\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mreason\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mResponseError\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n",
      "\u001b[0;31mConnectTimeout\u001b[0m: HTTPConnectionPool(host='www.santostang.com', port=80): Max retries exceeded with url: / (Caused by ConnectTimeoutError(<requests.packages.urllib3.connection.HTTPConnection object at 0x00000000077806D8>, 'Connection to www.santostang.com timed out. (connect timeout=0.001)'))"
     ]
    }
   ],
   "source": [
    "import requests\n",
    "link = \"http://www.santostang.com/\" \n",
    "r = requests.get(link, timeout= 0.001)"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.6.1"
  },
  "toc": {
   "colors": {
    "hover_highlight": "#DAA520",
    "navigate_num": "#000000",
    "navigate_text": "#333333",
    "running_highlight": "#FF0000",
    "selected_highlight": "#FFD700",
    "sidebar_border": "#EEEEEE",
    "wrapper_background": "#FFFFFF"
   },
   "moveMenuLeft": true,
   "nav_menu": {
    "height": "138px",
    "width": "252px"
   },
   "navigate_menu": true,
   "number_sections": true,
   "sideBar": true,
   "threshold": 4,
   "toc_cell": false,
   "toc_section_display": "block",
   "toc_window_display": false,
   "widenNotebook": false
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
